package com.adb.receivecontent.utility;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Pref_Link_Magnet {
	
	private static SharedPreferences Preferences_Link_Magnet = null;
	
	public static void openPref(){
		Preferences_Link_Magnet = Const.APPLICATION_CONTEXT.getSharedPreferences(Const.PREF_LINK_MAGNET_FILE, Context.MODE_PRIVATE);
	}
	
	public static String getValue(String key, String defaultValue)
	{
		Pref_Link_Magnet.openPref();
		String result = Pref_Link_Magnet.Preferences_Link_Magnet.getString(key, defaultValue);
		Pref_Link_Magnet.Preferences_Link_Magnet = null;
		return result;
	}
	
	public static void setValue(String key, String value)
	{
		Pref_Link_Magnet.openPref();
		Editor prefsPrivateEditor = Pref_Link_Magnet.Preferences_Link_Magnet.edit();
		prefsPrivateEditor.putString(key, value);
		prefsPrivateEditor.commit();
		prefsPrivateEditor = null;
		Pref_Link_Magnet.Preferences_Link_Magnet = null;
		
	}
	
	public static void removeKeyID(String keyID){
		
		if(keyID != null && keyID.length() > 0){
			
			Pref_Link_Magnet.openPref();
			Editor prefsPrivateEditor = Pref_Link_Magnet.Preferences_Link_Magnet.edit();
			prefsPrivateEditor.remove(keyID);	
			prefsPrivateEditor.commit();
			prefsPrivateEditor = null;
			Pref_Link_Magnet.Preferences_Link_Magnet = null;
		}
		
	}
	
	public static Map<String,String>  getAllKeySets(){
		Pref_Link_Magnet.openPref();
		return new HashMap<String,String>((Map<String,String>)Preferences_Link_Magnet.getAll());
	}
	
}
